$(function() {
	//	localStorage.clear()
	//	alert(JSON.stringify(localStorage))

	//	地址的处理
	if(localStorage.CityName) {
		$("#cityname").html(localStorage.CityName);

	} else {
		//采用新浪接口获取当前城市
//		var city = remote_ip_info['city'];
		//	mui.toast(city)

//		$("#cityname").html(city);

	}

	AjaxNoLPostFn('api/catalog/selectcatalog', {
		'parentsId': '0'
	}, function(jsondata) {

		//查询分类接口
		var str = '';
		$.each(jsondata.dataResultList, function(i, obj) {
			str += '<a class="mui-control-item" ><div  style="background:url(' + IMGUrl + '' + obj.classifyImage + ') no-repeat center center" data-id="' + obj.catalogId + '" class="classimg"></div><span>' + obj.nodeName + '</span></a>';

		});
		$(".classbox > div").html(str);
		for(var i = 0; i < $('.mui-control-item').length; i++) {
			(function(i) {
				$(".mui-control-item").eq(i).on("tap", function() {
					var title = $(this).find("span").text();
					window.location.href = 'search-page.html?catalogId=' + $(this).find("div").attr('data-id') + '&title=' + title + '';
				})

			})(i);
		}
	});

	AjaxNoLPostFn('api/bizrelatives/selecthot?page=1&pagesize=13', {
		'hotState': '1',
		'sorting': 'original_price',
		'tosort': 'desc'
	}, function(data) {
//		console.log("热销产品");
		//		热销产品
		var str = '';
		var obj1 = data.pageInfo.list[0].bizCommodityForSales;
		var obj2 = data.pageInfo.list[1].bizCommodityForSales;
		var obj3 = data.pageInfo.list[2].bizCommodityForSales;
		str += '<div class="mui-col-xs-5 mainleft" onclick="window.top.location.href=\'ProductDetail.html?commodityNumber=' + obj1.commodityNumber + '\'"  >' +
			'<div class="img100" style="background-image:url(' + IMGUrl + '' + obj1.mainPhoto + ') " ></div>' +
			'<p class="phide1" >' + obj1.title + '</p>' +
			'<p class="pricetext">￥' + (data.pageInfo.list[0].bizCommodityForSalePrices[0].presentPrice) / 100 + '</p>' +
			//			'<div class="buybtn">购买</div>' +

			'</div>' +
			'<div class="mui-col-xs-7 mainright"  >' +
			'<div class="mui-row"  onclick="window.top.location.href=\'ProductDetail.html?commodityNumber=' + obj2.commodityNumber + '\'" >' +
			'<div class="mui-col-xs-6 " >' +
			'<div class="img100" style="background-image:url(' + IMGUrl + '' + obj2.mainPhoto + ')"></div>' +
			'</div>' +
			'<div class="mui-col-xs-6 ">' +
			'<p class="phide1">' + obj2.title + '</p>' +
			'<p class="pricetext">￥' + (data.pageInfo.list[1].bizCommodityForSalePrices[0].presentPrice) / 100 + '</p>' +
			'</div>' +
			//			'<div class="buybtn">购买</div>' +

			'</div>' +

			'<div class="mui-row"  onclick="window.top.location.href=\'ProductDetail.html?commodityNumber=' + obj3.commodityNumber + '\'"  >' +
			'<div class="mui-col-xs-6 " > ' +
			'<div class="img100" style="background-image:url(' + IMGUrl + '' + obj3.mainPhoto + ')"></div>' +
			'</div>' +
			'<div class="mui-col-xs-6 " >' +
			'<p class="phide1">' + obj3.title + '</p>' +
			'<p class="pricetext">￥' + (data.pageInfo.list[2].bizCommodityForSalePrices[0].presentPrice) / 100 + '</p>' +
			'</div>' +
			//			'<div class="buybtn">购买</div>' +

			'</div>' +
			'</div>'

		$(".hotmainindexbox").html(str);

//		//华胜精选暂时用着热销接口
//		var jxstr = '';
//		$.each(data.pageInfo.list, function(i, obj) {
//			if(i < 4) {
//
//				if(i % 2 > 0) {
//					jxstr +=
//						'<div class="p2box-6 fleft" onclick="window.top.location.href=\'ProductDetail.html?commodityNumber=' + obj.bizCommodityForSales.commodityNumber + '\'">';
//				} else {
//					jxstr +=
//						'<div class="p2box-6" onclick="window.top.location.href=\'ProductDetail.html?commodityNumber=' + obj.bizCommodityForSales.commodityNumber + '\'">';
//
//				}
//				jxstr += '	<div class="pimg" style="background-image:url(' + IMGUrl + '' + obj.bizCommodityForSales.mainPhoto + ') ;"></div>' +
//					'	<p  class="phide1">' + obj.bizCommodityForSales.shortName + '</p>' +
//					'</div>';
//			}
//		});
//		$(".suggest").html(jxstr);
	})

	AjaxNoLGettFn('api/homepagebanner/selectall', {}, function(jsondata) {
		//查询banner接口 setBanner为1是即为banner

		if(jsondata.dataResultList.length > 0) {
			
			
			var str = '';
			//		最后一张
			$("#bannerdot").empty();
			str += ' <div class="mui-slider-item">' +
				'<a href="#">' +
				'<img src="' + IMGUrl + '' + jsondata.dataResultList[jsondata.dataResultList.length - 1].imageUrl + '">' +
				'</a>' +
				'</div> ';
			$.each(jsondata.dataResultList, function(idx, obj) {
				str += ' <div class="mui-slider-item">' +
					'<a href="#">' +
					'<img src="' + IMGUrl + '' + obj.imageUrl + '">' +
					'</a>' +
					'</div> ';

				$("#bannerdot").append('<div class="mui-indicator"></div>')
			});
			//第一张
			str += ' <div class="mui-slider-item">' +
				'<a href="#">' +
				'<img src="' + IMGUrl + '' + jsondata.dataResultList[0].imageUrl + '">' +
				'</a>' +
				'</div> ';

			$("#photo_content").html(str);
			$("#bannerdot:eq(0)").addClass("mui-active");

			var gallery = mui('.mui-slider');
			gallery.slider({
				interval: 3000 //自动轮播周期，若为0则不自动播放，默认为0；
			});
			mui('.mui-scroll-wrapper').scroll({
				deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
			});
		}

	})
	
	
	MuiAjaxFn('api/commoditdetails/selectallpage?page=1&pagesize=11', {'tosort':'asc','page':'0','pagerow':'10', 'sorting':'present_price'}, function(data) {
	
		//		最新产品
		var str = '';
		var obj1 = data.pageInfo.list[0];
		var obj2 = data.pageInfo.list[1];
		var obj3 = data.pageInfo.list[2];
		str += '<div class="mui-col-xs-5 mainleft" onclick="window.top.location.href=\'ProductDetail.html?commodityNumber=' + obj1.commodityNumber + '\'"  >' +
			'<div class="img100" style="background-image:url(' + IMGUrl + '' + obj1.mainPhoto + ') " ></div>' +
			'<p class="phide1" >' + obj1.title + '</p>' +
			'<p class="pricetext">￥' + (data.pageInfo.list[0].dataResultObj[0].presentPrice) / 100 + '</p>' +
			//			'<div class="buybtn">购买</div>' +

			'</div>' +
			'<div class="mui-col-xs-7 mainright"  >' +
			'<div class="mui-row"  onclick="window.top.location.href=\'ProductDetail.html?commodityNumber=' + obj2.commodityNumber + '\'" >' +
			'<div class="mui-col-xs-6 " >' +
			'<div class="img100" style="background-image:url(' + IMGUrl + '' + obj2.mainPhoto + ')"></div>' +
			'</div>' +
			'<div class="mui-col-xs-6 ">' +
			'<p class="phide1">' + obj2.title + '</p>' +
			'<p class="pricetext">￥' + (data.pageInfo.list[1].dataResultObj[0].presentPrice) / 100 + '</p>' +
			'</div>' +
			//			'<div class="buybtn">购买</div>' +

			'</div>' +

			'<div class="mui-row"  onclick="window.top.location.href=\'ProductDetail.html?commodityNumber=' + obj3.commodityNumber + '\'"  >' +
			'<div class="mui-col-xs-6 " > ' +
			'<div class="img100" style="background-image:url(' + IMGUrl + '' + obj3.mainPhoto + ')"></div>' +
			'</div>' +
			'<div class="mui-col-xs-6 " >' +
			'<p class="phide1">' + obj3.title + '</p>' +
			'<p class="pricetext">￥' + (data.pageInfo.list[2].dataResultObj[0].presentPrice) / 100 + '</p>' +
			'</div>' +
			//			'<div class="buybtn">购买</div>' +

			'</div>' +
			'</div>'

		$(".newmainindexbox").html(str);
		
		
		//华胜精选
		var jxstr = '';
		var jxstrcount = 0;
		$.each(data.pageInfo.list, function(i, obj) {
			if(obj.recommendState == 1){
//				console.log(/**/'.精选')
				if(jxstrcount < 4){
					jxstr +=
						'<div class="p2box-6" onclick="window.top.location.href=\'ProductDetail.html?commodityNumber=' + obj.commodityNumber + '\'">'+
					'	<div class="pimg" style="background-image:url(' + IMGUrl + '' + obj.mainPhoto + ') ;"></div>' +
					'	<p  class="phide1">' + obj.smallTitle + '</p>' +
					'</div>';	
					jxstrcount++;	
				}
				
			}
			
//			
//			if(i < 4) {
//		
//				if(i % 2 > 0) {
//					jxstr +=
//						'<div class="p2box-6 fleft" onclick="window.top.location.href=\'ProductDetail.html?commodityNumber=' + obj.bizCommodityForSales.commodityNumber + '\'">';
//				} else {
//					jxstr +=
//						'<div class="p2box-6" onclick="window.top.location.href=\'ProductDetail.html?commodityNumber=' + obj.bizCommodityForSales.commodityNumber + '\'">';
//
//				}
//				jxstr += '	<div class="pimg" style="background-image:url(' + IMGUrl + '' + obj.bizCommodityForSales.mainPhoto + ') ;"></div>' +
//					'	<p  class="phide1">' + obj.bizCommodityForSales.shortName + '</p>' +
//					'</div>';
//			}
		});
		$(".suggest ").html(jxstr);
		$(".suggest .p2box-6:odd").addClass("fleft");
//		$(".suggest").html(jxstr);
	})

})